package com.example.content.adapter.recycle

import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.content.R
import com.example.content.adapter.recycle.entity.MultiListItemEntity

/**
 * Created by zhudongao
 * Desc
 * Date 2020/10/7
 */
class MultiListAdapter : BaseMultiItemQuickAdapter<MultiListItemEntity, BaseViewHolder>() {

    init {

        addItemType(MultiListItemEntity.LIST_TEXT_TYPE, R.layout.drop_down_list_item)

        addItemType(
            MultiListItemEntity.MSG_OFFICIAL_ACTIVITY_TYPE,
            R.layout.item_official_activity_layout
        )
        addItemType(MultiListItemEntity.MSG_CHART_TYPE, R.layout.item_msg_layout)
        addItemType(MultiListItemEntity.MSG_REWARD_TYPE, R.layout.item_msg_reward_layout)

        addItemType(MultiListItemEntity.UP_PRODUCT_PHOTO_TYPE, R.layout.item_upload_image_layout)

        addItemType(MultiListItemEntity.ME_PRODUCT_SHOW_TYPE, R.layout.me_product_list_item_layout)
    }

    override fun convert(holder: BaseViewHolder, item: MultiListItemEntity) {
        when (holder.itemViewType) {
            MultiListItemEntity.GRID_NINE_IMAGE_TYPE -> {

            }
            MultiListItemEntity.LIST_TEXT_TYPE -> {
                val textView = holder.getView<TextView>(R.id.text)
                textView.text = item.contentText
            }
            MultiListItemEntity.MSG_OFFICIAL_ACTIVITY_TYPE -> {

            }
            MultiListItemEntity.MSG_CHART_TYPE -> {

            }
            MultiListItemEntity.MSG_REWARD_TYPE -> {

            }
            //我的页面作品item
            MultiListItemEntity.ME_PRODUCT_SHOW_TYPE -> {
                val image = holder.getView<ImageView>(R.id.image)
                Glide.with(image.context).load(item.contentText).into(image)
                val productType = holder.getView<ImageView>(R.id.product_type)
                val position = holder.layoutPosition % 2
                if (position == 0) {
                    productType.setImageResource(R.drawable.ic_video_select)
                } else {
                    productType.setImageResource(R.drawable.ic_photo)
                }
            }
            else -> {

            }
        }
    }
}